package com.starry.module.system.core.oauth2.controller.app;

import com.starry.core.common.domain.R;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.checkcode.domain.qo.CaptchaCreateQo;
import com.starry.module.system.api.checkcode.enums.GenerateCodeType;
import com.starry.module.system.core.checkcode.service.CheckCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.starry.core.common.constants.CodeType.APP_SMS_LOGIN;

/**
 * App验证码
 *
 * @author xiaoke
 */
@Tag(name = "App验证码")
@RestController
@RequestMapping("system/oauth2/code")
public class AppCodeController extends BaseController {

    private final CheckCodeService checkCodeService;

    public AppCodeController(CheckCodeService checkCodeService) {
        this.checkCodeService = checkCodeService;
    }

    /**
     * 发送登录验证码
     */
    @Operation(summary = "发送登录验证码")
    @PostMapping("sendLogin/{cellphone}")
    public R<Void> sendLogin(@PathVariable("cellphone") String cellphone) {
        CaptchaCreateQo captchaCreateQo = new CaptchaCreateQo();
        captchaCreateQo.setType(GenerateCodeType.SMS);
        captchaCreateQo.setCodeType(APP_SMS_LOGIN);
        captchaCreateQo.setCellphone(cellphone);
        checkCodeService.generate(captchaCreateQo);
        return success();
    }
}
